package com.shinheungcal.Solve;

import com.shinheungcal.IO.GearSpac;

public class SpanMeasurement {

	GearSpac spac;
	
	public SpanMeasurement(GearSpac spac) {
		this.spac = spac;
	}
	
	public double getSm1(double Zm1) {

		double m = spac.getModule();
		double a0 = Math.toRadians(spac.getPress_degree());
		double z1 = spac.getTeeth();
		double zm1 = Zm1;
		double x = spac.getAdd_teeth();
		
		double result;
		
		if (spac.getTorsion_degree() == 0) {
			result = (m * Math.cos(a0)) * (Math.PI * (zm1 - 0.5) + (z1 * inva(a0))) + (2 * m * x * Math.sin(a0));
		} else {
			double b0 = as(Math.toRadians(spac.getTorsion_degree()));
			result = (m * Math.cos(a0)) * (Math.PI * (zm1 - 0.5) + (z1 * inva(b0))) + (2 * m * x * Math.sin(a0));
		}
		
		return result;
	}
	
	public double getZm1() {
		return Math.round((spac.getPress_degree() * spac.getTeeth()) / 180);
	}
	
	private double inva(double radian_degree) {
		return Math.tan(radian_degree) - radian_degree;
	}
	
	private double as(double b0) {
		return Math.atan((Math.tan(spac.getPress_degree() / Math.cos(b0))));
	}
}
